package com.mvp.shq.washer.ui.wallet;

import com.mvp.shq.washer.entity.Bill;
import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.result.BillResult;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/24.
 */

public class WalletPresenter extends WalletConstract.Presenter {
    @Override
    public void onStart() {

    }

    @Override
    void getBills(int pageNo, int pageSize) {
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getId();
        model.getBills(token,userId,pageNo,pageSize)
                .subscribe(new BaseObserver<BillResult>(view) {
                    @Override
                    protected void onSuccees(BaseResult<BillResult> t) throws Exception {
                        if (t.isError()){
                            view.getBillsF(t.getMsg());
                        }else {
                            if (t.getData() == null){
                                List<Bill> bills = new ArrayList<Bill>();
                                view.getBillsS(bills);
                            }else {
                                view.getBillsS(t.getData().getList());
                            }
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        e.printStackTrace();
                        view.getBillsF("未知错误");
                    }
                });
    }
}
